package com.upb.webserver.role;

import com.upb.webserver.account.AccountService;
import com.upb.webserver.common.pojo.account.AccountCommon;
import com.upb.webserver.common.pojo.base.BaseResponse;
import com.upb.webserver.common.tools.JsonUtils;
import com.upb.webserver.dao.entity.TbRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @Autowired
    private AccountService accountService;


    /**
     * @param request
     * @return
     */
    @GetMapping(value = "all")
    public BaseResponse listRoleVoByPlatform(HttpServletRequest request) {
        log.info("start exec method [listRoleVoByPlatform]. ");
        //get AccountCommon
        AccountCommon accountCommon = accountService.getAccountCommon(request);
        List<TbRole> roleList = roleService.listRoleVoByPlatform(accountCommon.getPlatform());
        BaseResponse response = BaseResponse.initSuccess();
        response.setData(roleList);
        log.info("success exec method [listRoleVoByPlatform]. result:{}", JsonUtils.objToString(response));
        return response;
    }
}

